package br.com.components;

import java.util.Date;

import br.com.util.DateUtil;

public class DataPeriodo {
	
	/** ATRIBUTOS ********************/
	
	private Integer id;
	private Date dataInicial;
	private Date dataFinal;
	private String dataLabel;
	private String dataFieldFilter;
	
	public boolean validarObject(DataPeriodo dataPeriodo) {
		boolean retorno = dataPeriodo                      != null &&
				          dataPeriodo.getDataInicial()     != null &&
				          dataPeriodo.getDataFinal()       != null &&
				         (dataPeriodo.getDataFieldFilter() != null &&
				         !dataPeriodo.getDataFieldFilter().trim().equals(""));
		return retorno;
	}
	
	
	/** GET E SET'S ********************/
	
	public Date getDataInicial() {
		return dataInicial == null ? null : DateUtil.formatarDataInicial(this.dataInicial);
	}
	public Date getDataFinal() {
		return dataFinal == null ? null : DateUtil.formatarDataFinal(this.dataFinal);
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public void setDataInicial(Date dataInicial) {
		this.dataInicial = dataInicial;
	}
	
	public void setDataFinal(Date dataFinal) {
		this.dataFinal = dataFinal;
	}
	public String getDataLabel() {
		return dataLabel;
	}
	public void setDataLabel(String dataLabel) {
		this.dataLabel = dataLabel;
	}
	
	public String getDataFieldFilter() {
		return dataFieldFilter;
	}
	public void setDataFieldFilter(String dataFieldFilter) {
		this.dataFieldFilter = dataFieldFilter;
	}
	/********************************************************************/
	/**                        EQUALS E HASH CODE                      **/
	/********************************************************************/
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((dataFinal == null) ? 0 : dataFinal.hashCode());
		result = prime * result
				+ ((dataInicial == null) ? 0 : dataInicial.hashCode());
		result = prime * result
				+ ((dataLabel == null) ? 0 : dataLabel.hashCode());
		result = prime * result + id;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		DataPeriodo other = (DataPeriodo) obj;
		if (dataFinal == null) {
			if (other.dataFinal != null)
				return false;
		} else if (!dataFinal.equals(other.dataFinal))
			return false;
		if (dataInicial == null) {
			if (other.dataInicial != null)
				return false;
		} else if (!dataInicial.equals(other.dataInicial))
			return false;
		if (dataLabel == null) {
			if (other.dataLabel != null)
				return false;
		} else if (!dataLabel.equals(other.dataLabel))
			return false;
		if (id != other.id)
			return false;
		return true;
	}
	
	
}
